//
//  ApplyAuthListTableViewCell.swift
//  Venus
//
//  Created by qurongxiang on 2018/8/4.
//  Copyright © 2018年 zhaowang. All rights reserved.
//

import UIKit

class ApplyAuthListTableViewCell: UITableViewCell {
    
    fileprivate lazy var titleLabel = UILabel(UIColor.black, 14, "真实姓名")
    
    fileprivate lazy var textField = UITextField()
    
    fileprivate lazy var lineView = UIView()
    
    
    fileprivate var currentModelArr = ApplyModel()
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
}

extension ApplyAuthListTableViewCell {
    
    func configModel(modelArr:ApplyModel , index:IndexPath) {
        currentModelArr = modelArr
        titleLabel.text = modelArr.list[index.item].title
        if modelArr.list[index.item].placeholder.count != 0 {
            textField.placeholder = modelArr.list[index.item].placeholder
        }
        textField.text = modelArr.list[index.item].value
        textField.tag = index.item
        textField.addTarget(self, action: #selector(textFieldAddObersver(textField:)), for: .editingChanged)
    }
    
    
    @objc func textFieldAddObersver(textField:UITextField) {
        currentModelArr.list[textField.tag].value = textField.text!
    }
}

extension ApplyAuthListTableViewCell {
    func setupUI() {
        contentView.backgroundColor = UIColor.white
        contentView.addSubview(titleLabel)
        contentView.addSubview(textField)
        contentView.addSubview(lineView)
        
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(10)
            make.centerY.equalToSuperview()
        }
        
        textField.snp.makeConstraints { (make) in
             make.left.equalToSuperview().offset(100)
             make.top.bottom.right.equalToSuperview()
        }
        textField.font = UIFont.systemFont(ofSize: 14)
        textField.placeholder = "ddddd"
        
        
        lineView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().inset(10)
            make.bottom.equalToSuperview()
            make.height.equalTo(0.5)
        }
        lineView.backgroundColor = kColorC2
        
    }
}
